package com.exam.service.impl;

import com.exam.mapper.MessageMapper;
import com.exam.pojo.Message;
import com.exam.pojo.Score;
import com.exam.service.MessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Resource
    MessageMapper messageMapper;

    @Override
    public PageInfo<Message> queryPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Message> messages = messageMapper.queryAll();
        PageInfo<Message> pageInfo = new PageInfo<>(messages);
        return pageInfo;
    }

    @Override
    public int add(Message message) {
        return messageMapper.insert(message);
    }

    @Override
    public PageInfo<Message> queryPageByStudentId(Integer pageNum, Integer pageSize, Integer studentId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Message> messages = messageMapper.queryByStudentId(studentId);
        PageInfo<Message> pageInfo = new PageInfo<>(messages);
        return pageInfo;
    }

    @Override
    public Message queryById(Integer id) {
        return messageMapper.queryById(id);
    }

    @Override
    public int updateById(Message message) {
        return messageMapper.updateById(message);
    }

    @Override
    public int deteleById(Integer id) {
        return messageMapper.deteleById(id);
    }
}
